package com.tudouji.project.produce.controller;

import java.util.List;

import com.tudouji.project.organization.domain.Organization;
import com.tudouji.project.organization.service.IOrganizationService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.tudouji.framework.aspectj.lang.annotation.Log;
import com.tudouji.framework.aspectj.lang.enums.BusinessType;
import com.tudouji.project.produce.domain.Produceplan;
import com.tudouji.project.produce.service.IProduceplanService;
import com.tudouji.framework.web.controller.BaseController;
import com.tudouji.framework.web.domain.AjaxResult;
import com.tudouji.common.utils.poi.ExcelUtil;
import com.tudouji.framework.web.page.TableDataInfo;

/**
 * 生产计划Controller
 *
 * @author tudouji
 * @date 2022-06-01
 */
@RestController
@RequestMapping("/produce/plan")
public class ProduceplanController extends BaseController {
    @Autowired
    private IProduceplanService produceplanService;

    @Autowired
    private IOrganizationService organizationService;

    /**
     * 查询生产计划列表
     */
    @GetMapping("/list")
    public TableDataInfo list(Produceplan produceplan,String stats,String functionType) {
//        startPage();
        List<Produceplan> list = produceplanService.selectProduceplanList(produceplan, stats, functionType);
        return getDataTable(list);
    }

    /**
     * 生产成本录入获取生产计划列表
     */
    @GetMapping("/getPlans")
    public AjaxResult getPlans(String functionType) {
        List<Produceplan> list = produceplanService.selectProduceplanList(functionType);
        return AjaxResult.success(list);
    }

    /**
     * 新增生产计划
     */
    @Log(title = "生产计划", businessType = BusinessType.INSERT)
    @PostMapping("/save")
    public AjaxResult save(@RequestBody Produceplan produceplan) {
        return produceplanService.insertProduceplan(produceplan);
    }

    /**
     * @Description: 重启生产计划
     * @Author: xiaxl
     * @return:
     **/
    @GetMapping(value = "/enable/{guid}")
    public AjaxResult enable(@PathVariable("guid") String guid) {
        return produceplanService.enable(guid);
    }

    @PostMapping(value = "/finish")
    public AjaxResult finish(String planid,String confirmFlag) {
        return produceplanService.finish(planid,confirmFlag);
    }

    /**
     * 导出生产计划列表
     */
    @Log(title = "生产计划", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Produceplan produceplan,String status,String functionType) {
        List<Produceplan> list = produceplanService.selectProduceplanList(produceplan, status, functionType);
        ExcelUtil<Produceplan> util = new ExcelUtil<Produceplan>(Produceplan.class);
        return util.exportExcel(list, "plan");
    }

    /**
     * 获取生产计划详细信息
     */
    @GetMapping(value = "/{guid}")
    public AjaxResult getInfo(@PathVariable("guid") String guid) {
        return produceplanService.selectProduceplanById(guid);
    }

    /**
     * 删除生产计划
     */
    @Log(title = "生产计划", businessType = BusinessType.DELETE)
    @PostMapping("/{guid}")
    public AjaxResult remove(@PathVariable String guid) {
        return produceplanService.deleteProduceplanById(guid);
    }


    @GetMapping(value = "/getOrgbyWh")
    public AjaxResult getOrgbyWh() {
        return AjaxResult.success(organizationService.selectOrganizationList(new Organization()));
    }
}
